package com.Graphic_Salon.Action.Login.Action;

import java.util.List;

import org.hibernate.Session;
import com.opensymphony.xwork2.ActionSupport;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import com.Graphic_Salon.Action.Login.Entity.User_Info;

public class LoginAction extends ActionSupport{
	private String user_Name;
	private String password;
	
	
	public String getUser_Name() {
		return user_Name;
	}


	public void setUser_Name(String userName) {
		user_Name = userName;
	}


	public String getPassword() {
		return password;
	}


	public void setPassword(String password) {
		this.password = password;
	}


	public String execute(){		
		String loginState = "loginSuc";;
		User_Info loginUser = null;
		Configuration cfg = new Configuration();
		SessionFactory sf = cfg.configure().buildSessionFactory();
		Session session = sf.openSession();
		session.beginTransaction();
		List userList = session.createSQLQuery("SELECT USER_ID,USER_NAME,PASSWORD FROM USER_INFO WHERE USER_NAME='admin' AND PASSWORD='admin'").list();
		loginUser = (User_Info) userList.get(0);
		if (loginUser.getUser_Id() == "" || loginUser.getUser_Id() == null)
			loginState = "loginFail";
		session.getTransaction().commit();
		session.close();
		sf.close();		
		
		return loginState;
	}

	
}
